<template>
  <div class="role-edit">
    <el-form :model="form">
      <el-input v-model="form.id" auto-complete="off" hidden></el-input>
      <el-form-item label="角色名称" :label-width="formLabelWidth">
        <el-input v-model="form.roleName" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item label="排序" :label-width="formLabelWidth">
        <el-input v-model.number="form.sortNumber" type="age" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item label="描述" :label-width="formLabelWidth">
        <el-input v-model="form.roleDesc" type="textarea"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('change-state',false)">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.dialog-footer {
  text-align: center;
}
.el-cascader {
  width: 100%;
}
</style>
<script>
import { Loading } from 'element-ui'
export default {
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formLabelWidth: '120px',
      form: {
        id: '',
        roleName: '',
        sortNumber: 1,
        roleDesc: ''
      }
    }
  },
  beforeDestroy() {
    this.$off('reload')
    this.$off('change-state')
  },
  methods: {
    initDialogData(_id) {
      const loading = Loading.service({ target: '.role-edit' })
      this.$axios.get('/org/role/get-by-id?id=' + _id)
        .then(res => {
          loading.close()
          this.form = res.data.obj
        }).catch(err => {
          loading.close()
          this.$message.error(err)
        })
    },
    handleChange(value) {
    },
    save() {
      const loading = Loading.service({ target: '.role-edit' })
      this.$axios.put('/org/role/edit', this.form)
        .then(res => {
          loading.close()
          if (res.data.code === 200) {
            this.$emit('change-state', false)
            this.$emit('reload')
            this.$message.success(res.data.msg)
          } else {
            this.$message.success(res.data.msg)
          }
        }).catch(() => {
          loading.close()
        })
    }
  }
}
</script>
